package com.xwli.springcloud.service.impl;

import com.xwli.springcloud.service.AsyncTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Slf4j
@Service
public class AsyncTaskServiceImpl implements AsyncTaskService {

    @Async("doSomethingExecutor")
    @Override
    public CompletableFuture<String> testOne() throws InterruptedException {
        log.info("方法一:睡眠5s");
        Thread.sleep(5000);
        return CompletableFuture.completedFuture("testone-成功");
    }

    @Async("doSomethingExecutor")
    @Override
    public CompletableFuture<String> testTwo() throws InterruptedException {
        log.info("方法二:睡眠10s");
        Thread.sleep(10000);
        return CompletableFuture.completedFuture("testtwo-成功");
    }

    @Async("doSomethingExecutor")
    @Override
    public CompletableFuture<Integer> testThree() throws InterruptedException {
        log.info("方法三:睡眠6s");
        Thread.sleep(6000);
        return CompletableFuture.completedFuture(3333);
    }

    @Async("doSomethingExecutor")
    public CompletableFuture<Integer> testFour() throws InterruptedException {
        log.info("方法四:睡眠4s");
        Thread.sleep(4000);
        return CompletableFuture.completedFuture(4444);
    }
}
